home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch12 / TrFish.cls < prev    next >
Encoding:
Visual Basic class definition  |  1999-06-17  |  943 b   |  41 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "TransFish"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. ' A fisheye transformation.
  16.  
  17. Implements Transformation
  18.  
  19. ' The center of transformation.
  20. Public Cx As Single
  21. Public Cy As Single
  22. Public Radius As Single
  23.  
  24. ' Transform the point (X, Y).
  25. Private Sub Transformation_Transform(X As Single, Y As Single)
  26. Dim r As Single
  27. Dim new_r As Single
  28. Dim dx As Single
  29. Dim dy As Single
  30.  
  31.     dx = X - Cx
  32.     dy = Y - Cy
  33.     r = Sqr(dx * dx + dy * dy)
  34.     If r < 1 Then Exit Sub
  35.  
  36.     new_r = Radius * (1 - 1 / (r / Radius * 2 + 1))
  37.  
  38.     X = Cx + dx / r * new_r
  39.     Y = Cy + dy / r * new_r
  40. End Sub
  41.